<template>
  <div>
    <ZgNewPage
      ref="page"
      title="委托待办列表"
      :conditions="conditions"
      @condition="onSearch"
      :openCondition="true"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :adminWidth="140"
      :labelCol="7"
      @search="onSearch"
      @admin="btnClick"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          :title="h.label"
        >
          <template slot-scope="record">
            {{ record[h.code] }}
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
    <ZgDrawer ref="zgDrawer" width="100%" v-model="visible">
      <HandleIndex @close="onClose" :flowInfo="flowInfo" ref="HandleIndex"></HandleIndex>
    </ZgDrawer>
  </div>
</template>

<script>
import HandleIndex from '@/views/autoflow/handle/Index'

export default {
  components: {
    HandleIndex
  },
  data () {
    return {
      flowInfo: null,
      visible: false,
      pageOpt: {
        showConditionBtn: false
      },
      headers: [
        { code: 'flowName', label: '流程名称', width: 240, isShow: true, sort: 0 },
        { code: 'instCode', label: '流程实例', width: 240, isShow: true, sort: 0 },
        { code: 'stepCode', label: '当前环节编号', width: 240, isShow: true, sort: 0 },
        { code: 'stepName', label: '当前环节名称', width: 240, isShow: true, sort: 0 }
      ],
      conditions: [
        { code: 'flowName', compType: '单行文本', label: '流程名称', defaultVal: '' },
        { code: 'instanceNo', compType: '单行文本', label: '流程编码', defaultVal: '' },
        { code: 'stepName', compType: '单行文本', label: '环节名称', defaultVal: '' },
        {
          code: 'flowInstState',
          compType: '下拉选择',
          label: '流程状态',
          defaultVal: '',
          extra: {
            下拉选项: [
              { value: '0', label: '待处理' },
              { value: '1', label: '进行中' },
              { value: '2', label: '已办结' }
            ]
          }
        }
      ],
      dataBtns: [
        {
          key: 1,
          name: '去处理',
          type: 'primary',
          icon: 'fa-plane',
          isShow: () => {
            return true
          }
        }
      ]
    }
  },
  methods: {
    onSearch (param) {
      if (param.flowInstState !== undefined && param.flowInstState !== '' && param.flowInstState !== '0') {
        this.dataBtns = []
      } else {
        this.dataBtns = [
          {
            key: 1,
            name: '去处理',
            type: 'primary',
            icon: 'fa-plane',
            isShow: () => {
              return true
            }
          }
        ]
      }
      // 加载表头
      console.log(param, 'param')
      this.$http.post(
        '/zg-autoflow/flow/settleWorkflowInstance/getTodoWorkflowInstancePage',
        {
          ...param,
          type: 1
        },
        (res) => {
          console.log(res, 'res')
          this.$refs.page.endSearch({
            total: Number(res.total),
            list: res.records
          })
        }
      )
    },
    btnClick (val) {
      console.log(val)
      if (val.key === 1) {
        this.$set(this, 'flowInfo', {
          instCode: val.obj.instCode,
          stepInstCode: val.obj.stepInstCode
        })
        console.log(this.flowInfo)
        this.$refs.zgDrawer.open()
      }
    },
    onClose () {
      this.visible = false
    }
  }
}
</script>

<style scoped>
</style>
